/**
* Created by Administrator on 2025/5/28.
* */
#include "AppDelegate.h"
#include "GlobalParameters.h"
#include <string>
#include "AIPCNet/AIPCNet.h"
#include "AIPCTrainController/AIPCTrainController.h"
#include "MyDeviceReader/MyDeviceReader.h"
#include "MyDeviceWriter/MyDeviceWriter.h"
#include "EthernetReader.h"
#include "EthernetWriter.h"

void AppDelegate::onConfigure(device_config_t *config){
    config->calculationPoolSize=8;
    config->globalParametersInstance = GlobalParameters::shareInstance();
    config->deviceId=8;
    config->servicePort=55261;
    config->ip="192.168.1.115";
    config->userVersion="1.0";
}

void AppDelegate::onStart(){
    REGISTER_RUNTIME_LOADED_CLASSES(AIPCNet,MyDeviceReader,MyDeviceWriter,AIPCTrainController);
    auto aiPCNet = new AIPCNet();
    auto aiPCTrainController = new AIPCTrainController();

    auto radarlabWriter = new MyDeviceWriter();
    aiPCNet->addDeviceWriter(0,radarlabWriter,1024);

    auto radarlabWriter_1 = new MyDeviceWriter();
    aiPCTrainController->addDeviceWriter(0,radarlabWriter_1,1024);

    auto radarlabWriter_2 = new EthernetWriter(TCP,"192.168.1.115",6675,true);
    aiPCNet->addDeviceWriter(1,radarlabWriter_2,1024);

    auto radarlabReader = new MyDeviceReader();
    radarlabReader->addTaskModule(aiPCNet,0,1024);
    radarlabReader->addTaskModule(aiPCTrainController,0,1024);

    auto radarlabReader_1 = new MyDeviceReader();
    radarlabReader_1->addTaskModule(aiPCNet,1,1024);

    auto radarlabReader_2 = new EthernetReader(TCP,6672);
    radarlabReader_2->addTaskModule(aiPCTrainController,1,1024);

    aiPCTrainController->setLaunchPolicy(LaunchMode_OR,LaunchCondition());
    REGISTER_INSTANCES(aiPCNet,radarlabReader,radarlabReader_1,radarlabWriter,radarlabWriter_2,aiPCTrainController,radarlabReader_2,radarlabWriter_1);
}
